package com.tempjob.app.aspect;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hui
 * @Date 2024/11/8 11:28
 **/
@Slf4j
@Component
public class CustomExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        if (ex instanceof HttpRequestMethodNotSupportedException) {
            String requestURI = request.getRequestURI();
            String method = request.getMethod();
            log.error("Request method '{}' not supported for URL: {}", method, requestURI);
        }
        // 你可以在这里返回一个自定义的错误页面或视图
        return null;
    }

}
